/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Roles {
    public static boolean insertRole(Entity.Role rol){
        try {
            String sql = "insert into tblRoles values(?,?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, rol.get_RoleID());
            ps.setString(2, rol.get_RoleName());
            ps.setString(3, rol.get_Description());
            ps.setBoolean(4, rol.is_Status());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Roles.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateRole(Entity.Role rol){
        try {

            String sql = "update tblRoles set RoleName=?, Description=?, Status=? where RoleID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, rol.get_RoleName());
            ps.setString(2, rol.get_Description());
            ps.setBoolean(3, rol.is_Status());
            ps.setString(4, rol.get_RoleID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Roles.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static void deleteRole(String strRoleID){
        try {
            String sql = "delete from tblRoles where RoleID = '" + strRoleID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Roles.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
}
